using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using DAL;
using BUS;
using Utility;

public partial class admin_A_HinhThucThanhToan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loaddata();
        }
        
    }
    private void loaddata()
    {
        
        Criteria cri = new Criteria();
        int total = 0;
        pthinhthucthanhtoan.PageSize = 5;
        if (txttenhinhthuc.Text != "")
        {
            cri.add(Condition.AND, tbHinhThuc_ThanhToanColums.TENHINHTHUC_THANHTOAN, Condition.LIKE, txttenhinhthuc.Text);
        }
        if (txtmahinhthuc.Text != "")
        {
            cri.add(Condition.AND, tbHinhThuc_ThanhToanColums.MAHINHTHUC_THANHTOAN, Condition.EQUAL, int.Parse(txtmahinhthuc.Text));
        }

        tbHinhThuc_ThanhToanColection lhttt = HinhThucThanhToan_BUS.Get(cri.Criter, pthinhthucthanhtoan.CurrentIndex, pthinhthucthanhtoan.PageSize, tbHinhThuc_ThanhToanColums.MAHINHTHUC_THANHTOAN.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = lhttt;
        Repeater1.DataBind();
        pthinhthucthanhtoan.ItemCount = total;


    }
    
    public bool IsNumeric(string val)
    {
        double result;
        return double.TryParse(val, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.CurrentInfo, out result);
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {

            HinhThucThanhToan_DTO httt = (HinhThucThanhToan_DTO)e.Item.DataItem;
            HyperLink hplsua = (HyperLink)e.Item.FindControl("hplsua");
            hplsua.NavigateUrl = "~/admin/A_HinhThucThanhToan_update.aspx?mahthuc=" + httt.MaHinhThucThanhToan.ToString();
            ////hplsua.NavigateUrl = "~/admin/A_loaihang_update.aspx";
            Image hinh = (Image)e.Item.FindControl("hinhanh");
            hinh.ImageUrl = "~/photos/thumb/" + httt.HinhAnh;

        }
    }
    protected void bttimkiem_Click(object sender, EventArgs e)
    {
        //string maloai = txtmahinhthuc.Text;

        //if (IsNumeric(maloai) == false)
        //{
        //    txtmahinhthuc.ForeColor = System.Drawing.Color.Red;
        //    // loaddata();
        //    return;
        //}
        //else
        //{

        //    txtmahinhthuc.ForeColor = System.Drawing.Color.Black;
        loaddata();

        //}
    }
    protected void pthinhthucthanhtoan_Command(object sender, CommandEventArgs e)
    {
        pthinhthucthanhtoan.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        loaddata();
    }
    protected void lbt_x_Click(object sender, EventArgs e)
    {


        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cxoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cxoa.Checked == true)
            {
                HiddenField hdf = (HiddenField)Repeater1.Items[i].FindControl("hdmaht");
                int ma = int.Parse(hdf.Value);
                HinhThucThanhToan_BUS.Delete(ma);

            }
        }
        Response.Redirect(Request.RawUrl);


    }


   
}
